package com.augurit.common.common.http.kt.request

import com.augurit.common.common.http.kt.client.BaseRetrofitFactory
import com.augurit.common.common.http.kt.client.IRetrofitFactory
import retrofit2.Retrofit

/**
 *  author : yanghaozhang
 *  date : 2022/5/4 20:13
 *  description :
 */

interface IPlatFormStrategy {

    fun getRetrofit(): Retrofit

    fun <T> getService(kClass: Class<T>): T
}

abstract class BasePlatFormStrategy : IPlatFormStrategy {
    val factory: IRetrofitFactory = BaseRetrofitFactory.instance

    val serviceMap = mutableMapOf<Class<*>, Any?>()

    override fun getRetrofit(): Retrofit {
        return factory.getRetrofit(getBaseUrl())
    }

    override fun <T> getService(kClass: Class<T>): T {
        return serviceMap[kClass] as T ?: getRetrofit().create(kClass).also {
            serviceMap[kClass] = it
        }
    }

    abstract fun getBaseUrl(): String
}

object ShuiWuPlatForm : BasePlatFormStrategy() {

    override fun getBaseUrl(): String {
        return ""
    }

}

object SanFangPlatForm : BasePlatFormStrategy() {

    override fun getBaseUrl(): String {
        return ""
    }

}